<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Annonces extends MY_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->library('grocery_CRUD');

		$this->load->model('Annonces_model'); 
	}
	
	function _page_output($output = null)
	{	
	    $this->data['js_files'] = $output->js_files;
		$this->data['css_files'] = $output->css_files;
		$this->data['output'] = $output->output;		
		$this->render();
	}
	
	function annonces()
	{
		$output = $this->grocery_crud->render();

		$this->_page_output($output);
	}
	
	function index()
	{
		$this->_page_output((object)array('output' => '' , 'js_files' => array() , 'css_files' => array()));
	}	
	
	function annonces_management()
	{
		try{
			$crud = new grocery_CRUD();
			
			$crud->unset_print();
			$crud->unset_export();
			$crud->set_theme('datatables');
			$crud->set_table('annonces');
			$crud->set_subject('Annonce');
			
			$crud->set_field_upload('file_url','assets/uploads/files');
								
			$output = $crud->render();
			
			$this->_page_output($output);
			
		}catch(Exception $e){
			show_error($e->getMessage().' --- '.$e->getTraceAsString());
		}
	}
	
	function list_annonces() {
		
		$this->data['annonces'] = $this->Annonces_model->get_annonces(); 
		
		$this->render(); 
	}
	
	function view_annonce($id) {
		
		$this->data['annonce_data'] = $this->Annonces_model->get_annonce($id); 
		
		$this->render();
	}
	
}